Use StreamableFile from @nestjs/common to stream a Node.js Readable stream to the response. Combine with @Res({ passthrough: true }) to set Content-Type and Content-Disposition headers while still returning through NestJS's response pipeline. This avoids buffering the entire file in memory.
StreamableFile pipes the readable stream to the response without buffering the entire content.
@Res({ passthrough: true }) sets headers while keeping NestJS's pipeline active — interceptors still run.
Pass a Buffer or Readable stream to StreamableFile — it handles both.
Set Content-Disposition: attachment to prompt a browser download instead of inline display.
For large datasets use a database cursor or query stream instead of loading all records first.